from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import settings
from app.api.endpoints import dataset, predict, model

app = FastAPI(
    title=settings.PROJECT_NAME,
    openapi_url=f"{settings.API_V1_STR}/openapi.json"
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(
    dataset.router,
    prefix=f"{settings.API_V1_STR}/datasets",
    tags=["datasets"]
)
app.include_router(
    predict.router,
    prefix=f"{settings.API_V1_STR}/predict",
    tags=["prediction"]
)
app.include_router(
    model.router,
    prefix=f"{settings.API_V1_STR}/model",
    tags=["model"]
)

@app.get("/")
async def root():
    return {
        "message": "欢迎使用垃圾邮件分类API",
        "docs_url": "/docs"
    }

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(
        "main:app",
        host=settings.HOST,
        port=settings.PORT,
        reload=True
    ) 